
//基础 接口地址
//后台接口
let baseUrl = "http://192.168.100.100:17001"
//运动接口 
let baseUrlTrue = "http://192.168.100.100:17002"
//ws接口
let wsUrl = "http://192.168.100.100:16002"

//请求函数
const requester = (options:any)=>{
	if(options.baseUrl ){
		return new Promise((resolve,reject)=>{
			uni.request({
				url:baseUrlTrue+options.url,
				method:options.method || "GET",
				data:options.data || {},
				header:options.headers || {},
				success: (res:any) => {
					if(res.data.success == 401 && res.data.message == "token失效"){
						uni.navigateTo({
							url:'/pages/login/login',
						})
						uni.showToast({
							title: 'token超时,请重新登录',
							icon:"none"
						})
					}else{
						resolve(res)
					}
				},
				fail: (err) => {
					uni.showToast({
						title: '请求接口失败！',
						icon:"none"
					})
					reject(err)
					
				}
			})
		})
	}else{
		return new Promise((resolve,reject)=>{
			uni.request({
				url:baseUrl+options.url,
				method:options.method || "GET",
				data:options.data || {},
				header:options.headers || {},
				success: (res:any) => {
					if(res.data.success == 401 && res.data.message == "token失效"){
						uni.navigateTo({
							url:'/pages/login/login',
						})
						uni.showToast({
							title: 'token超时,请重新登录',
							icon:"none"
						})
					}else{
						resolve(res)
					}
				},
				fail: (err) => {
					uni.showToast({
						title: '请求接口失败！',
						icon:"none"
					})
					reject(err)
					
				}
			})
		})
	}
	
}

export default requester;